<template>
<div>
  <el-dialog :title="$t('DEVICE.ADDEVICES')" :close-on-click-modal="false"  :visible.sync="show" v-if="!isPhone"
   class="my_devices_dialog pcShow" :before-close="cancle">
    <div class="my_devices_add">
      <p>{{$t('DEVICE.ORDERID')}}</p>
      <el-form :model="form" :rules="rules" ref="form" >
         <el-form-item  prop="order_no">
          <el-input v-model="form.order_no" clearable>
            <i slot="prefix" class="iconfont icon-search_normal"></i>
          </el-input>
         </el-form-item>
      </el-form>

      <!-- <p>{{$t('DEVICE.CHECKORDERID')}}</p> -->
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancle">{{$t('DEVICE.CANCLE')}}</el-button>
      <el-button type="search" :loading="loading" @click="submitForm">{{$t('DEVICE.SEARCH')}}</el-button>
    </span>
  </el-dialog>
  <el-dialog  :close-on-click-modal="false"  :show-close="false" :visible.sync="show" v-if="isPhone"
   class="my_devices_dialog phoneShow" :before-close="cancle">
    <p class="my_devices_header" slot="title">
      <span class="back" @click="cancle">Back</span>
      <span class="my_devices_header_title">{{$t('DEVICE.ADDEVICES')}}</span>
      <span class="blue" @click="submitForm">Search</span>
    </p>
    <div class="my_devices_add"   >
     <p>{{$t('DEVICE.ORDERID')}}</p>
      <el-form :model="form" :rules="rules" ref="form" >
         <el-form-item  prop="order_no">
          <el-input v-model="form.order_no" >
            <i slot="suffix" class="iconfont icon-search_normal" @click="submitForm"></i>
          </el-input>
         </el-form-item>
      </el-form>
    </div>
  </el-dialog>
</div>

 
</template>

<script>
import { mapGetters } from 'vuex'
import { search } from '@/api/personalCenter/devices.js'
export default {
  data () {
    return {
      form: {
        order_no: '',
      },
      rules: {
        order_no: [
          { required: true, trigger: 'blur' ,message: this.$t('DEVICE.ORDERIDCOTTECT')},
        ],
      },
      loading: false
    }
  },
  props: {
    show: Boolean,
    closeDialog:Function,
    idList: Array
  },
  watch: {
    show: function() {
      if(!this.$parent.isBack) {
        this.form.order_no = ''
        this.$refs.form.clearValidate()
      }
    }
  },
  computed: {
    ...mapGetters(['isPhone']),
  },
  methods: {
    cancle() {
      this.$emit('closeDialog', 1)
    },
    submitForm(){
      this.$refs.form.validate((valid) => {
        if(valid){
          this.formSubmit()
        } else {
          return false
        }
      })
    },
    formSubmit () {
      this.loading = true
      let params = this.form
      search(params).then(res => {
        if(res.state == 1) {
          this.$parent.deviceSearchList = res.data
          this.$emit('closeDialog', 2)
          this.loading = false
        }
      })
    }
  }
}
</script>

<style>

</style>